package com.zhiyou100.api.java8_date;

import java.time.*;
import java.util.Date;

/**
 * Date转java8新日期
 * java8新日期转Date
 */
public class Demo6 {

    public static void main(String[] args) {
        //先将Date日期转成时间戳
        Instant instant = new Date().toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDate localDate = instant.atZone(zoneId).toLocalDate();
        System.out.println("localDate = " + localDate);
        //将LocalDate转成Date
        LocalDate date = LocalDate.of(2022, 01, 15);
        Instant instant1 = date.atStartOfDay().toInstant(ZoneOffset.UTC);
        Date date1 = Date.from(instant1);
        System.out.println("date1 = " + date1);

    }

}
